package com.haiyou.common.form;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;

import javax.validation.GroupSequence;
import javax.validation.constraints.AssertTrue;
import javax.validation.constraints.Pattern;
import javax.validation.groups.Default;


/**
 * 忘记密码表单
 */
@Data
@ApiModel(value = "忘记密码表单")
public class UpdatePasswordForm {

    private interface Order1 {
    }

    private interface Order2 {
    }

    @GroupSequence({Default.class, Order1.class, Order2.class})
    public interface GroupValid {
    }

    @ApiModelProperty(value = "验证码")
    @NotBlank(message = "验证码不能为空")
    private String authCode;

    @ApiModelProperty(value = "密码")
    @NotBlank(message = "密码不能为空")
    @Length(min = 6, max = 16, message = "密码长度6-16位", groups = {Order1.class})
    private String password;

    @ApiModelProperty(value = "新密码")
    @NotBlank(message = "新密码不能为空")
    @Length(min = 6, max = 16, message = "新密码长度6-16位", groups = {Order1.class})
    private String newPassword;

    @ApiModelProperty(value = "手机号")
    @NotBlank(message = "手机号不能为空")
    @Pattern(regexp = "^1[3-9]\\d{9}$", message = "手机号不正确")
    private String phone;

    @AssertTrue(message = "两次密码不一致!", groups = {Order2.class})
    public boolean isPasswordsEquals() {
        return password.equals(newPassword);
    }

}
